from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from goods.models import GoodsChannel, GoodsChannelGroup, GoodsCategory
from meiduo_admin.serializer.channel import GoodsChannelSerializer, GoodsChannelGroupSerializer
from meiduo_admin.utils import UserPageNum
from meiduo_admin.serializer.channel import GoodsCategorySerializer



class GoodsChannelView(ModelViewSet):

    queryset = GoodsChannel.objects.all()
    serializer_class = GoodsChannelSerializer
    pagination_class = UserPageNum
    permission_classes = [IsAdminUser]

    def groups(self,request):

        data = GoodsChannelGroup.objects.all()
        ser = GoodsChannelGroupSerializer(data,many=True)
        return Response(ser.data)

    def categorys(self,request):


        conn = GoodsCategory.objects.filter(parent_id = None)
        ser = GoodsCategorySerializer(conn,many=True)
        return Response(ser.data)




